<!-- 角色选择下拉框 -->
<template>
  <el-select clearable
             ref="xdtzKey"
             :value="value"
             class="ele-block"
             :placeholder="placeholder"
             @input="updateValue">
    <el-option v-for="item in data"
               :key="item.id"
               :value="item.id"
               :idssss="item.type"
               :label="item.name" />
  </el-select>
</template>

<script>
import { listRoles } from '@/api/system/role';

export default {
  props: {
    // 选中的数据(v-modal)
    value: [Number, String],
    // 提示信息
    placeholder: {
      type: String,
      default: '请选择角色'
    }
  },
  data () {
    return {
      data: [],

    };
  },
  created () {
    /* 获取角色数据 */
    listRoles()
      .then((list) => {
        this.data = list;
      })
      .catch((e) => {
        this.$message.error(e.message);
      });
  },
  methods: {
    updateValue (value) {
      this.$nextTick(() => {
        setTimeout(() => {
          console.log(this.$refs['xdtzKey'].selected.$attrs?.idssss)
          if (this.$refs['xdtzKey'].selected.$attrs?.idssss == 1) {
            this.$emit('isShowStore', false);
          } else {
            this.$emit('isShowStore', true);
          }

        }, 200)

      })
      this.$emit('input', value);
    }
  }
};
</script>
